package cs633.util;

import java.sql.*;
import java.util.ResourceBundle;

public class DBManager {
	private static DBManager _instance = null;
	Connection conn = null;
	ResourceBundle rb = null;
	
	private DBManager() {
		init();
	}
	public static DBManager getInstance() {
		if (_instance == null) {
			_instance = new DBManager();
		}
		return _instance;
	}
	private void init() {
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			rb = ResourceBundle.getBundle("resource");
		} catch (Exception e) {
			System.out.println("Error: " + e.getMessage());
		}
	}
	
	public Connection getConn() {
		try {
			String str = rb.getString("driver");
			if (str != null) 
				conn = DriverManager.getConnection(str);
			
		} catch (SQLException sqle) {
			System.out.println("Error: " + sqle.getMessage());
		}
		return conn;
	}
	public void dropConn(Connection conn) {
		try {
			conn.close();
		} catch (SQLException sqle) {
			System.out.println("Error: " + sqle.getMessage());
		}
	}
}
